<template>
  <information />

  <!-- <div class="btn-use" @click="showToast" style="margin-top: 73px">
    使用设备
  </div>
  <div class="btn-err" @click="jump">故障报修</div> -->
</template>
<script setup>
  import { basicData } from '../store/data.js';
  import information from '../components/information.vue';
  import { getCurrentInstance, onBeforeMount } from 'vue';
  import { useRouter, useRoute } from 'vue-router';
  const { proxy } = getCurrentInstance();
  const store = basicData();
  const router = useRouter();
  const route = useRoute();
  //扫码进入页面 获取设备id
  onBeforeMount(() => {
    /*   console.log(route.query.id, 199);  271 */
    proxy.$axios
      .post(`${proxy.baseUrl}/phase/getEquipment`, { id: 423 })
      .then((res) => {
        if (res.data.code == 0) {
          alert(res.data.msg);
        } else {
          store.$patch((state) => {
            state.basicData = res.data.data;
            state.department_name = res.data.data.department.name;
          });
          jump();
        }
      })
      .catch((res) => {
        console.log(res, 1998);
        // message({ text: "服务器错误" });
      });
  });
  //提报故障
  const jump = () => {
    router.push({
      path: '/home',
      /* query: {
        id: 1,
      }, */
    });
  };
  // 使用设备
  const showToast = () => {
    if (store.basicData.status == 2) {
      alert('该设备已经被停用');
      return false;
    }
    proxy.$axios
      .post(`${proxy.baseUrl}/phase/employ`, {
        equipment_id: store.basicData.id,
      })
      .then((res) => {
        // message({ text: res.data.msg });
        alert(res.data.msg);
      })
      .catch((res) => {
        console.log(res);
      });
  };
</script>
<style scoped></style>